package xyz.xiangyushui.dao.user.member;

import java.util.List;
import java.util.Map;

import xyz.xiangyushui.dao.Dao;
import xyz.xiangyushui.javaBean.membership.MembershipProfile;

public class MembershipProfileDao extends Dao {
	public void update(MembershipProfile mp) {
		db.executeUpdate(
				"update membershipProfile set gender=?,age=?,address=? where userName=?",
				new Object[] { mp.getGender(), mp.getAge(), mp.getAddress(),
						mp.getUserName() });
	}

	public void addNewMembershipProfile(String userName) {
		db.executeUpdate("insert into membershipProfile values(?,?,?,?,?)",
				new Object[] { userName, "男", 0, "南京","000000" });
	}

	public MembershipProfile getProfile(String userName) {
		MembershipProfile mp = new MembershipProfile();
		List<Object> list = db.excuteQuery(
				"select * from membershipProfile where userName=?",
				new Object[] { userName });
		if (!list.isEmpty()) {
			@SuppressWarnings("unchecked")
			Map<String, Object> map = (Map<String, Object>) list.get(0);
			mp.setUserName((String) map.get("userName"));
			mp.setGender((String) map.get("gender"));
			mp.setAddress((String) map.get("address"));
			mp.setAge((int) map.get("age"));
		}
		return mp;
	}
	
	public String getBankCard(String userName){
		List<Object> list = db.excuteQuery(
				"select bankCard from membershipProfile where userName=?",
				new Object[] { userName });
		if(!list.isEmpty()){
			@SuppressWarnings("unchecked")
			Map<String, Object> map = (Map<String, Object>) list.get(0);
			return (String) map.get("bankCard");
		}
			return null;
	}
	
	public void updateBankCard(String userName,String bankCard){
		db.executeUpdate(
				"update membershipProfile set bankCard=? where userName=?",new Object[]{bankCard,userName});
	}
	
	public void delete(String userName){
		db.executeUpdate("delete from membershipProfile where userName=?", new Object[]{userName});
	}
}
